{% extends "base.html" %}

{% block content %}
    <div class="card">
        <div class="card-header">
            <h2 class="text-center">学生信息列表</h2>
        </div>
        <div class="card-body">
            {% if students %}
            <div class="table-responsive">
                <table class="table table-striped table-hover">
                    <thead class="thead-dark">
                        <tr>
                            <th>学号</th>
                            <th>姓名</th>
                            <th>性别</th>
                            <th>年龄</th>
                            <th>专业</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for student in students %}
                        <tr>
                            <td>{{ student.student_id }}</td>
                            <td>{{ student.name }}</td>
                            <td>{{ student.gender }}</td>
                            <td>{{ student.age }}</td>
                            <td>{{ student.major.name }}</td>
                            <td>
                                <a href="{{ url_for('main.update_student', student_id=student.id) }}" class="btn btn-primary btn-sm">编辑</a>
                                <button type="button" class="btn btn-danger btn-sm" data-toggle="modal" data-target="#deleteModal{{ student.id }}">删除</button>
                            </td>
                        </tr>
                        
                        <!-- 删除确认模态框 -->
                        <div class="modal fade" id="deleteModal{{ student.id }}" tabindex="-1" role="dialog" aria-labelledby="deleteModalLabel{{ student.id }}" aria-hidden="true">
                            <div class="modal-dialog" role="document">
                                <div class="modal-content">
                                    <div class="modal-header">
                                        <h5 class="modal-title" id="deleteModalLabel{{ student.id }}">确认删除</h5>
                                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                            <span aria-hidden="true">&times;</span>
                                        </button>
                                    </div>
                                    <div class="modal-body">
                                        确定要删除学生 <strong>{{ student.name }}</strong> 的信息吗？此操作不可恢复。
                                    </div>
                                    <div class="modal-footer">
                                        <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
                                        <form action="{{ url_for('main.delete_student', student_id=student.id) }}" method="post">
                                            <button type="submit" class="btn btn-danger">删除</button>
                                        </form>
                                    </div>
                                </div>
                            </div>
                        </div>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
            {% else %}
            <div class="alert alert-info text-center">
                暂无学生信息，请添加新学生。
            </div>
            {% endif %}
        </div>
        <div class="card-footer text-center">
            <a href="{{ url_for('main.add_student') }}" class="btn btn-success">添加学生</a>
        </div>
    </div>
{% endblock %}